using UnityEngine;
using System.Collections;

public class SoundWaveControl : MonoBehaviour
{
    #region Attributes

    public float ratio = 1.0f;
    public float speed = 1.0f;
    public float distortionSpeedFactor = 2.0f;

    private Vector3 scaleTo;
    private float accSpeedTime;
    private float distortion;
    #endregion

    #region Unity Methods

    void Start()
    {
        this.scaleTo = Vector3.one * this.ratio;
        this.accSpeedTime = 0;
        this.distortion = this.renderer.material.GetFloat("_BumpAmt");
    }

	void Update () 
    {
        this.accSpeedTime += this.speed * Time.deltaTime;
        this.transform.localScale = Vector3.Lerp(this.transform.localScale, this.scaleTo, this.accSpeedTime);
        this.distortion -= this.distortionSpeedFactor * Time.deltaTime * (this.ratio / this.speed);
        this.renderer.material.SetFloat("_BumpAmt", this.distortion);

        if (this.transform.localScale.x >= this.ratio &&
            this.transform.localScale.z >= this.ratio)
        {
            Object.Destroy(this.gameObject);
        }
    }

    #endregion
}
